﻿//
// 获取数据方法
//
function fnGetData(entity, condition, order, IsDesc) {
    var _Data = null;
    $.ajax({
        type: "GET",
        url: "/extendpage/data/jsondata.aspx",
        data: { r: Math.random(), pageindex: 1, pagesize: 500, entity: entity, condition: condition, order: (order == undefined) ? "" : order, Desc: (IsDesc == undefined ? "" : IsDesc) },
        async: false,
        success: function (data) {

            if (data == '{"total":0,"rows":}') {
                _Data = null;
            }
            else {
                _Data = eval("(" + data + ")");
            }
        },
        error: function (e) {
            return;
        }
    }
    );
    return _Data;
}


function fnGetSingleData(entity, condition, pageindex) {
    var _data = null;
    var index = typeof (pageindex) == "undefined" ? 1 : pageindex;
    $.ajax({
        type: "GET",
        url: "/extendpage/data/jsondata.aspx",
        data: { r: Math.random(), pageindex: index, pagesize: 500, entity: entity, condition: condition, type: 1 },
        async: false,
        success: function (data) {
            //_data = eval("(" + data + ")");
            //update zengtongchun 2016-12-17
            if (data!="") {
                _data = eval("(" + data + ")");
            }
        },
        error: function (e) {
            return {};
        }
    }
    );
    return _data;
}

function fnGetEntityInstance(entity, condition) {
    var _data = fnGetSingleData(entity, condition);
    if (_data != null) {
        return _data[0];
    }
    return null;
}

/* 请求Ajax 带返回值
--------------------------------------------------*/
function getAjax(url, parm, callBack) {
    $.ajax({
        type: 'post',
        dataType: "text",
        //async: false,
        url: url,
        data: parm,
        cache: false,
        async: false,
        success: function (data) {
            if (callBack) {
                callBack(data);
            }
        }
    });
}
